<template>
  <div style="padding:0px;">
    <el-form :model="dialogForm1" :rules="rules1" ref="dialogForm1" :label-width="formLabelWidth" style="margin-bottom:25px;">
      <div style="display:flex;height:35px;">
        <el-form-item label="原业务人员" prop="oldId" style="flex:1;">
          <el-select v-model="dialogForm1.oldId" placeholder="请选择原业务人员" :disabled="!salesmanDialogFormVisible.isAdd">
            <el-option label="请选择原业务人员" value=""> </el-option>
            <el-option v-for="(item, index) in yewuyuan" :label="item.realname" :value="item.id" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="新业务人员" prop="newId" style="flex:1;">
          <el-select v-model="dialogForm1.newId" placeholder="请选择新业务人员" :disabled="!salesmanDialogFormVisible.isAdd">
            <el-option label="请选择新业务人员" value=""></el-option>
            <el-option v-for="(item, index) in yewuyuan" :label="item.realname" :value="item.id" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-button style="margin-left:10px;" type="primary" @click="submitConfirmForm('dialogForm1')">提 交</el-button>
      </div>
    </el-form>
    <el-form :model="dialogForm2" :rules="rules2" ref="dialogForm2" :label-width="formLabelWidth" style="margin-bottom:25px;">
      <div style="display:flex;height:35px;">
        <el-form-item label="原资源人员" prop="oldId" style="flex:1;">
          <el-select v-model="dialogForm2.oldId" placeholder="请选择原资源人员" :disabled="!salesmanDialogFormVisible.isAdd">
            <el-option label="请选择原资源人员" value=""> </el-option>
            <el-option v-for="(item, index) in ziyuan" :label="item.realname" :value="item.id" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="新业务人员" prop="newId" style="flex:1;">
          <el-select v-model="dialogForm2.newId" placeholder="请选择新资源人员" :disabled="!salesmanDialogFormVisible.isAdd">
            <el-option label="请选择新资源人员" value=""></el-option>
            <el-option v-for="(item, index) in ziyuan" :label="item.realname" :value="item.id" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-button style="margin-left:10px;" type="primary" @click="submitConfirmForm('dialogForm2')">提 交</el-button>
      </div>
    </el-form>
    <el-form :model="dialogForm3" :rules="rules3" ref="dialogForm3" :label-width="formLabelWidth">
      <div style="display:flex;height:35px;">
        <el-form-item label="原地推人员" prop="oldId" style="flex:1;">
          <el-select v-model="dialogForm3.oldId" placeholder="请选择原地推人员" :disabled="!salesmanDialogFormVisible.isAdd">
            <el-option label="请选择原地推人员" value=""> </el-option>
            <el-option v-for="(item, index) in ditui" :label="item.realname" :value="item.id" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="新业务人员" prop="newId" style="flex:1;">
          <el-select v-model="dialogForm3.newId" placeholder="请选择新地推人员" :disabled="!salesmanDialogFormVisible.isAdd">
            <el-option label="请选择新地推人员" value=""></el-option>
            <el-option v-for="(item, index) in ditui" :label="item.realname" :value="item.id" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-button style="margin-left:10px;" type="primary" @click="submitConfirmForm('dialogForm3')">提 交</el-button>
      </div>
    </el-form>
    <el-container>
      <el-footer>
		<h5>警告：</h5>
		<h5>1、适用情况：A、老员工离职，其全部业务转给另一员工跟进；B、内部业务调整，甲的全部业务转给乙跟进；</h5>
		<h5>2、不适用情况：部分业务转移，请慎用此操作，不可逆。</h5>
	  </el-footer>
    </el-container>
    <div style="text-align:right;margin-top:15px;">
      <el-button @click="returnBack">返 回</el-button>
    </div>
  </div>
</template>
<script>
  import router from '@/router';
  import agentHttp from '@/utils/agentHttp.js'
  import {
    require,
    phone,
    decimalFour,
    numOrEnglish,
    max100
  } from '@/utils/rules.js'
  export default {
    created() {
      this.getStatusMap();
    },
    props: ['salesmanDialogFormVisible', 'tableData'],
    data() {
      return {
        formLabelWidth: '120px',
        yewuyuan: {},
        ditui: {},
        ziyuan: {},
        requestUrl: "",
        //弹窗或者查看页面信息
        dialogForm1: {
          oldId: "",
          newId: ""
        },
        dialogForm2: {
          oldId: "",
          newId: ""
        },
        dialogForm3: {
          oldId: "",
          newId: ""
        },
        rules1: {
          oldId: [require('请选择原业务人员', {
            type: "number",
            trigger: "change"
          })],
          newId: [require('请选择新业务人员', {
            type: "number",
            trigger: "change"
          })]
        },
        rules2: {
          oldId: [require('请选择原资源人员', {
            type: "number",
            trigger: "change"
          })],
          newId: [require('请选择新资源人员', {
            type: "number",
            trigger: "change"
          })]
        },
        rules3: {
          oldId: [require('请选择原地推人员', {
            type: "number",
            trigger: "change"
          })],
          newId: [require('请选择新地推人员', {
            type: "number",
            trigger: "change"
          })]
        }

      }
    },
    methods: {

      returnBack() {
        this.salesmanDialogFormVisible.dialogFormVisible = false;
      },
      submitConfirmForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.addData(formName);
          } else {
            this.$nextTick(() => {
              setTimeout(() => {
                this.$message.warning(document.getElementsByClassName('el-form-item__error')[0].innerText);
              }, 500)
              return false;
            })
          }
        });
      },
      addData(formName) {
        if (formName == "dialogForm3") {
          //地推
          this.requestUrl = 'adminApi/admin/dealer/update_push';
        } else if (formName == "dialogForm2") {
          //资源人员
          this.requestUrl = 'adminApi/admin/dealer/update_resource';
        } else if (formName == "dialogForm1") {
          //业务人员
          this.requestUrl = 'adminApi/admin/dealer/update_business';
        }
        agentHttp.putJson(this.requestUrl, this[formName]).then((data) => {
          if (data.success) {

            this.$emit('refreshTableData', null);
            this.salesmanDialogFormVisible.dialogFormVisible = false;
            this.$message.success(data.data || "修改成功");
          }
        })
      },
      //获取人员列表
      getStatusMap() {
        agentHttp.get('adminApi/admin/dealer/view/get_basic_map').then((data) => {
          this.yewuyuan = data.data.yewuyuan;
          this.ziyuan = data.data.ziyuan;
          this.ditui = data.data.ditui;
        })
      }
    }
  };

</script>
